<template>
  <div class="app-container">
    <!-- 查询条件区域-->
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="72px">
      <el-form-item label="摄像头ip" prop="ip">
        <el-input v-model="queryParams.ip" placeholder="请输入摄像头ip" clearable @keyup.enter.native="handleQuery"
          size="small" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="small" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="small" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <!--增删改查按钮区域-->
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete"
          v-hasPermi="['nssc:alarmInformation:remove']">删除</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>
    <!--  数据列表区域-->
    <el-table v-loading="loading" :data="cameraResultList" @selection-change="handleSelectionChange"
      :cell-style="{ borderColor: 'rgb(1 5 43)' }" :header-cell-style="{ borderColor: 'rgb(1 5 43)' }">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="摄像头ip" align="center" prop="ip" />
      <el-table-column label="管廊编号" align="center" prop="poolNum">
        <template slot-scope="scope">
          <span>{{ scope.row.poolNum }}管廊</span>
        </template>
      </el-table-column>
      <el-table-column label="摄像头位置" align="center" prop="position">
        <template slot-scope="scope">
          <span>位于管廊{{ scope.row.position }}侧</span>
        </template>
      </el-table-column>
      <el-table-column label="告警时间" align="center" prop="creater_time">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.creater_time) }}</span>
        </template>
      </el-table-column>
      <!--<el-table-column label="图片地址" align="center" prop="pictureUrl" />-->
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="200">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-camera" @click="handleView(scope.row)"
            v-hasPermi="['nssc:alarmInformation:query']">告警视频</el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
            v-hasPermi="['nssc:alarmInformation:remove']">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!--列表分页区域-->
    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" style="background:rgb(1 5 43);" />
    <!-- 查看弹出 -->
    <el-dialog :title="title" :visible.sync="open" width="750px" hight="500px" append-to-body>
      <el-form ref="form" :model="form" label-width="80px" class="el-Dial">
        <videoPlayer class="vjs-custom-skin videoPlayer" ref="videoplayer" :playsinline="true" style="width:730px;height: 400px" :options="playerOptions" customEventName="changed">
        </videoPlayer>
      </el-form>
    </el-dialog>
  </div>
</template>
<script>
import { delResult, getResult, listResult } from "@/api/nssc/alarmInformation/alarmInformation";
import { videoPlayer } from 'vue-video-player';
import 'video.js/dist/video-js.css';
import 'vue-video-player/src/custom-theme.css';
export default {
  data() {
    return {
      VideoUrl: '', // 存储请求返回的视频地址
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      //复选删除时弹框内容
      ipNames: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 站点表格数据
      cameraResultList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 8,
        ip: undefined
      },
      playerOptions: {
        language: "zh-CN",
        playbackRates: [0.7, 1.0, 1.5, 2.0],// 播放速度
        muted: false,// 默认情况下将会消除任何音频
        autoplay: false,// 如果true,浏览器准备好时开始回放。
        controls: true, //不显示暂停、声音、进度条组件
        loop: false, // 视频一结束就重新开始。
        fluid: true, // 当true时，Video.js player将拥有流体大小。换句话说，它将按比例缩放以适应其容器。
        notSupportedMessage: "此视频暂无法播放，请稍后再试", // 允许覆盖Video.js无法播放媒体源时显示的默认信息。
        sources: [
          {
            src: "",
            type: 'video/mp4',
          },
        ],
        controlBar: {
          timeDivider: false, // 当前时间和持续时间的分隔符
          durationDisplay: true, // 显示持续时间
          remainingTimeDisplay: true, // 是否显示剩余时间功能
          fullscreenToggle: true, // 是否显示全屏按钮
        }
      },
      // 表单参数
      form: {},
    };
  },
  //初始化配置列表
  created() {
    this.getList();
  },
  components: {
    videoPlayer,
  },
  methods: {
    /** 查询布防结果列表 */
    getList() {
      this.loading = true;
      listResult(this.queryParams).then(response => {
        this.cameraResultList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: undefined,
        ip: undefined,
        user: undefined,
        port: undefined,
        psw: undefined,
        poolNum: undefined,
        position: undefined
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.ipNames = selection.map(item => item.ip)
      this.single = selection.length != 1
      this.multiple = !selection.length
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids
      const ipNames = row.ip || this.ipNames
      this.$modal.confirm('是否确认删除ip名称为"' + ipNames + '"的数据项？').then(function () {
        return delResult(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => { });
    },
    /**
     * 查看视频
     */
    handleView(row) {
      if(row.pictureUrl!=""){
        console.log("row.pictureUrl=="+row.pictureUrl)
          this.open = true;
          this.title = "查看原视频";
          this.playerOptions.sources[0].src = row.pictureUrl;
        }else{
          this.$modal.msg("未查到原视频！");
      }
      this.reset();
      const id = row.id || this.ids
      getResult(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "告警视频";
      });
    }
  }
};
</script>
<style lang="scss" scoped>
.el-Dial{
  display: flex;
  justify-content: center;
  align-items: center;
  ::v-deep .el-dialog__body{
    padding: 0 !important;
    z-index: 99;
  }
}
</style>

